﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UniMana.Utils.Controls;

namespace UniMana.Data
{
    public class Training_TrainingProgramInfo
    {
         #region /*Không thay đổi*/
            public bds m_bds = new bds();
            public void Save()
            {
                m_data.m_DCSave.SubmitChanges();
            }
            public void Delete()
            {
                m_bds.DeleteCurrent();
            }
            #endregion /*Không thay đổi*/
            private DBMain m_data = new DBMain();
            private bool m_bExits = false;
            #region [Properties - Thuộc tính]
            public Training_TrainingProgram Properties
            {
                get { return m_bds.Current as Training_TrainingProgram; }
            }
            #endregion
            public Training_TrainingProgramInfo(int level, int strainingTypeKey, int courseKey, int majorKey)
            {
                var IQuery = m_data.m_DCSave.Training_TrainingPrograms.Where(tb => tb.Catalogue_LevelKey == level && 
                                                                            tb.Catalogue_TrainingTypeKey == strainingTypeKey &&
                                                                            tb.Catalogue_CourseKey == courseKey &&
                                                                            tb.Catalogue_MajorKey == majorKey);
                m_bds.DataSource = IQuery;
                var Row = IQuery.FirstOrDefault();
                if (Row == null)
                {
                    Row = new Training_TrainingProgram();
                    m_bds.Add(Row);
                }
            }

            public Training_TrainingProgramInfo(string _strID)
            {
                var iQuery = this.m_data.m_DCSave.Training_TrainingPrograms.Where(p => p.ID == _strID);
                this.m_bds.DataSource = iQuery;
                var row = iQuery.FirstOrDefault();
                this.m_bExits = true;
                if (row == null)
                {
                    this.m_bExits = false;
                    row = new Training_TrainingProgram();
                    row.ID = _strID;
                    this.m_bds.Add(row);
                    this.m_bds.MoveLast();
                }
            }
            public Training_TrainingProgramInfo(int _iTrainingProgramKey)
            {
                var IQuery = m_data.m_DCSave.Training_TrainingPrograms.Where(tb => tb.Training_TrainingProgramKey == _iTrainingProgramKey);
                m_bds.DataSource = IQuery;
                var Row = IQuery.FirstOrDefault();
                if (Row == null)
                {
                    Row = new Training_TrainingProgram();
                    m_bds.Add(Row);
                }
            }
            
            //thi tot nghiep
            public Training_TrainingProgramInfo(int iLevel = 0, int iCourse = 0, int iMajor = 0)
            {
                var Iquery = m_data.m_DCSave.Training_TrainingPrograms.Where(p => p.Catalogue_CourseKey == iCourse &&
                                                    p.Catalogue_LevelKey == iLevel && p.Catalogue_MajorKey == iMajor);
                m_bds.DataSource = Iquery;
                var Row = Iquery.FirstOrDefault();
                if (Row == null)
                {
                    Training_TrainingProgram program = new Training_TrainingProgram();
                    program.Catalogue_CourseKey = iCourse;
                    program.Catalogue_LevelKey = iLevel;
                    program.Catalogue_MajorKey = iMajor;
                    Row = program;
                    //m_bds.Add(Row);
                    //m_bds.MoveLast();
                }
            }
    }
}
